package com.demoku.web.application.demoAdmin.impl;

import java.util.List;

import javax.inject.Named;

import org.iff.infra.util.BeanHelper;
import org.iff.infra.util.MapHelper;
import org.iff.infra.util.mybatis.plugin.Page;
import org.iff.infra.util.mybatis.service.Dao;
import org.springframework.transaction.annotation.Transactional;

import com.demoku.web.application.demoAdmin.ClassTypeApplication;
import com.demoku.web.application.demoAdmin.vo.ClassTypeVO;
import com.demoku.web.domain.demoAdmin.ClassType;

/**
 * @author autoCode
 */
@Named("classTypeApplication")
@Transactional
public class ClassTypeApplicationImpl implements ClassTypeApplication {

	@Override
	public void removeClassType(String classTypeId) {
		ClassType.remove(classTypeId);
	}

	@Override
	public ClassTypeVO saveClassType(ClassTypeVO vo) {
		ClassType a = new ClassType();
		BeanHelper.copyProperties(a, vo);
		a.save();
		ClassTypeVO copyProperties = BeanHelper.copyProperties(new ClassTypeVO(), a);
		return copyProperties;
	}

	@Override
	public ClassTypeVO getClassTypeVO(String classTypeId) {
		return BeanHelper.copyProperties(new ClassTypeVO(), ClassType.get(classTypeId));
	}

	@Override
	public List<ClassTypeVO> findAll(Page pages) {
		List<ClassType> list = Dao.queryList("ClassType_Mapping.findAll",
				MapHelper.toMap("page", pages));
		pages.setRows(list);
		return pages.toPage(ClassTypeVO.class).getRows();
	}

	@Override
	public Page pageFindAll(Page pages) {
		List<ClassType> list = Dao.queryList("ClassType_Mapping.findAll",
				MapHelper.toMap("page", pages));
		pages.setRows(list);
		return pages.toPage(ClassTypeVO.class);
	}
	
	@Override
	public Page pageFindAllClassType(ClassTypeVO vo, Page pages) {
		
		List<ClassType> list = Dao.queryList("ClassType_Mapping.pageFindClassType",
				MapHelper.toMap("page", pages , "name", vo.getName()));
		pages.setRows(list);
		return pages.toPage(ClassTypeVO.class);
	}

}
